package com.lanou.liuqixin.datebasedemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.liuqixin.datebasedemo.custom.LinearChartView;
import com.lanou.liuqixin.datebasedemo.R;

import java.util.List;

/**
 * Created by dllo on 17/4/19.
 */

public class UhaoFragment extends Fragment implements View.OnClickListener {
    private TextView titleTv, uhaoTv;
    private ImageView leftIv, rightIv, firstPointIv, secondPointIv, threePointIv, fourPointIv, fivePointIv;
    private String[] titles = new String[]{
            "油耗统计曲线", "最近一年油耗统计曲线", "最近半年油耗统计曲线", "最近三个月油耗统计曲线", "同城同车型油耗基准线"
    };
    private int count = 1;
    private int num = 4;
    private LinearChartView chartView;
    int[] one = new int[]{2,1,4,3,5,9,1,4,8,6,7,3,5,9,4,3,2,1};
    int[] two = new int[]{1,5,3,4, 2,10,11,1,7,2,3,4};
    int[] three = new int[]{11,10,7,2,9,1};
    int[] four = new int[]{6, 13, 9};
    int[] five = new int[]{5, 2, 7, 8, 13, 8, 11, 12, 6, 2, 7, 4};


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_uhao, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        titleTv = (TextView) view.findViewById(R.id.main_title_tv);
        uhaoTv = (TextView) view.findViewById(R.id.uhao_tv);
        leftIv = (ImageView) view.findViewById(R.id.uhao_left_iv);
        rightIv = (ImageView) view.findViewById(R.id.uhao_right_iv);
        firstPointIv = (ImageView) view.findViewById(R.id.point_one_iv);
        secondPointIv = (ImageView) view.findViewById(R.id.point_two_iv);
        threePointIv = (ImageView) view.findViewById(R.id.point_three_iv);
        fourPointIv = (ImageView) view.findViewById(R.id.point_four_iv);
        fivePointIv = (ImageView) view.findViewById(R.id.point_five_iv);
        chartView = (LinearChartView) view.findViewById(R.id.first_uhao);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        switchRound(0);
        leftIv.setOnClickListener(this);
        rightIv.setOnClickListener(this);







    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.uhao_left_iv:
                if (num == 0) {
                    switchRound(num);
                    titleTv.setText(titles[0]);
                    count = 1;
                    num = 4;
                } else if (num == 4) {
                    switchRound(num);
                    titleTv.setText(titles[num]);
                    count = 0;
                    num = 3;
                } else if (num == 3) {
                    switchRound(num);
                    titleTv.setText(titles[num]);
                    count = 4;
                    num = 2;
                } else if (num == 2) {
                    switchRound(num);
                    titleTv.setText(titles[num]);
                    count = 3;
                    num = 1;
                } else if (num == 1) {
                    switchRound(num);
                    titleTv.setText(titles[num]);
                    count = 2;
                    num = 0;
                }
                break;
            case R.id.uhao_right_iv:
                if (count == 0) {
                    switchRound(count);
                    titleTv.setText(titles[count]);
                    num = 4;
                    count = 1;

                } else if (count == 1) {
                    switchRound(count);
                    titleTv.setText(titles[count]);
                    num = 0;
                    count = 2;

                } else if (count == 2) {
                    switchRound(count);
                    titleTv.setText(titles[count]);
                    num = 1;
                    count = 3;
                } else if (count == 3) {
                    switchRound(count);
                    titleTv.setText(titles[count]);
                    num = 2;
                    count = 4;
                } else if (count == 4) {
                    switchRound(count);
                    titleTv.setText(titles[count]);
                    num = 3;
                    count = 0;
                }
                break;

        }


    }

    private void switchRound(int count) {

        if (count == 0) {
            firstPointIv.setImageResource(R.mipmap.point2);
            secondPointIv.setImageResource(R.mipmap.point);
            threePointIv.setImageResource(R.mipmap.point);
            fourPointIv.setImageResource(R.mipmap.point);
            fivePointIv.setImageResource(R.mipmap.point);
            titleTv.setText(titles[0]);
            String[] name = new String[]{"2016", "2017", "2018"};
            chartView.setTotal(one);
            chartView.setNames(name);
            chartView.setTvSizes(3);
            chartView.setNums(18);

        } else if (count == 1) {
            firstPointIv.setImageResource(R.mipmap.point);
            secondPointIv.setImageResource(R.mipmap.point2);
            threePointIv.setImageResource(R.mipmap.point);
            fourPointIv.setImageResource(R.mipmap.point);
            fivePointIv.setImageResource(R.mipmap.point);
            chartView.setTotal(two);
            String[] name = new String[]{"5", "6", "7", "8", "9", "10", "11", "12", "2017", "2", "3", "4"};
            chartView.setNames(name);
            chartView.setTvSizes(12);
            chartView.setNums(12);
        } else if (count == 2) {
            firstPointIv.setImageResource(R.mipmap.point);
            secondPointIv.setImageResource(R.mipmap.point);
            threePointIv.setImageResource(R.mipmap.point2);
            fourPointIv.setImageResource(R.mipmap.point);
            fivePointIv.setImageResource(R.mipmap.point);
            String[] name = new String[]{"11", "12", "2017", "2", "3", "4"};
            chartView.setTotal(three);
            chartView.setNames(name);
            chartView.setTvSizes(6);
            chartView.setNums(6);
        } else if (count == 3) {
            firstPointIv.setImageResource(R.mipmap.point);
            secondPointIv.setImageResource(R.mipmap.point);
            threePointIv.setImageResource(R.mipmap.point);
            fourPointIv.setImageResource(R.mipmap.point2);
            fivePointIv.setImageResource(R.mipmap.point);
            chartView.setTotal(four);
            String[] name = new String[]{"2", "3", "4"};
            chartView.setNames(name);
            chartView.setTvSizes(3);
            chartView.setNums(3);
        } else if (count == 4) {
            firstPointIv.setImageResource(R.mipmap.point);
            secondPointIv.setImageResource(R.mipmap.point);
            threePointIv.setImageResource(R.mipmap.point);
            fourPointIv.setImageResource(R.mipmap.point);
            fivePointIv.setImageResource(R.mipmap.point2);
            String[] name = new String[]{"5", "6", "7", "8", "9", "10", "11", "12", "2017", "2", "3", "4"};
            chartView.setTotal(five);
            chartView.setNames(name);
            chartView.setTvSizes(12);
            chartView.setNums(12);

        }
        chartView.MyNotify();

    }


}
